// [src_rely] lcctoolbox_filebox.cpp
#ifndef LCCTOOLBOX_FILEBOX
#include<cstdint>
#include<queue>
#include<deque>
#include"lcctoolbox_markset.hpp"// originstr
#include"lcctoolbox_block.hpp"// block


namespace LccToolbox{





LCCTOOLBOX_API_FILEBOX extern const char* searchPos(const char* str,const char* symbol,bool atBack =false);
template<class... Ts>
const char* searchStr(const char* str, const char* symbol, const char* match, char endchar, Ts&&... blockstrSlots);




constexpr size_t filemaxsize=65536000;
// constexpr size_t opSlotCount=32;

// enum class OPtype{
// 	insert,
// 	remove
// };

// type|global ind|insert str|delete size|row|col
// typedef attribute<OPtype,size_t,originstr,size_t,size_t,size_t> FileOP;



struct fileLine{
	size_t BeginSide=0;
	size_t EndSide=0;
	bool inuse=false;
};




// txt just can read as no-binary, but can save as binary
// binary just can read as binary, and save as binary
class fileBox{
protected:
	originstr filename;
	bool record=false;// show is this fileBox's data is usefull or not
	bool is_binary=false;

	Block data;
	
	block<fileLine> IndListofLine;
	// std::queue<FileOP> fileop;
	// std::deque<FileOP> tempRz;

	LCCTOOLBOX_API_FILEBOX void reset();
public:
	LCCTOOLBOX_API_FILEBOX fileBox(const char* =nullptr,bool=false);// t mean txt, b mean binary, else is default, in read is t, in save is recorded,else t

	LCCTOOLBOX_API_FILEBOX bool read(const char*,bool=false);
	LCCTOOLBOX_API_FILEBOX void save(const char* =nullptr,bool=false);

	// edit
	LCCTOOLBOX_API_FILEBOX size_t insert(size_t,const void*,size_t=0);
	LCCTOOLBOX_API_FILEBOX size_t remove(size_t,size_t);
	template<class... Ts> size_t insert(size_t,Ts...);
	template<class... Ts> size_t remove(size_t,Ts...);

	// after read/edit
	// make edit to data
	LCCTOOLBOX_API_FILEBOX void sort();
	LCCTOOLBOX_API_FILEBOX size_t freshLenth();

	LCCTOOLBOX_API_FILEBOX const char*from();
	LCCTOOLBOX_API_FILEBOX char*content();
	LCCTOOLBOX_API_FILEBOX const char* content() const;
	LCCTOOLBOX_API_FILEBOX size_t lenth();
	// number of line

	LCCTOOLBOX_API_FILEBOX Block& origin(bool record=true);
	LCCTOOLBOX_API_FILEBOX const Block& origin() const;
};




}// namespace LccToolbox




#include"inl/lcctoolbox_filebox.inl"

#define LCCTOOLBOX_FILEBOX
#endif